Page({
  data:{
    collectArticle:[],
    isEmpty:false
  },
  onLoad(){
    this.getCollectArticle()
  },
  async getCollectArticle(page=1,limit=10){
    const {errno,data:{list}}= await wx.http.get('/user/userDataList',{
      page,
      limit,
      type:'1'
    })
    if(errno !== 0 ) return wx.utils.toast('数据加载失败！')
    this.setData({
      isFinshed:list.totalPages > page,
      collectArticle:list.data,
      isEmpty:list.data.length !==0
    })
  },

  // 取消收藏
  async cancelCollect(ev){
    this.setData({collectArticle:this.data.collectArticle.filter(item => item.id !== ev.mark.id)})  
    await wx.http.get('/user/userDataHandle',{action:'del',type:1,article_id:ev.mark.id})
    wx.utils.toast('删除成功!')
  },
  // 分页
  onScorllBotton(){
    if(!this.data.isFinshed) return wx.utils.toast('到底了')
    this.getCollectArticle(++this._page)
  }
})